Print one to n


Posted by Christy on 2022-04-19

Description: Write a function that accepts a number n and print number one to n

function print(n) {

}

print(1);
// 1

print(3);
// 1
// 2
// 3

print(9);
// 1
// 2
// 3
// 4
// 5
// 6
// 7
// 8
// 9

Answer:

function print(n) {
  for (let i = 1; i <= n; i++) {
    console.log(i);
  }
}

print(1);
print(3);
print(9);









Related Posts

資料庫的好夥伴:Redis

資料庫的好夥伴:Redis

我要成為前端工程師的學習筆記:HTML & CSS 篇 - Box Model、區塊水平置中、文字水平調整 Day7

我要成為前端工程師的學習筆記:HTML & CSS 篇 - Box Model、區塊水平置中、文字水平調整 Day7

讀書筆記-JavaScript技術手冊4: 物件進階語法

讀書筆記-JavaScript技術手冊4: 物件進階語法


Comments